home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 41.zip / BS1 part 41 / Lattice C v5.02 d4.adf / examples / debugger / dbstr.cpr < prev    next >
Text File  |  1988-11-07  |  1KB  |  48 lines

  1. /* 
  2. DBSTR -- Dump memory as bytes for a given BSTR
  3.   DBSTR (<variable> | <address> | <range>)
  4.    >dbstr var         /* Dumps the BSTR pointed to by var      */
  5.    >dbstr 0x82034     /* Dumps the BSTR at location 0x002080d0 */
  6. Note that a BSTR is an address shifted right 2 pointing to a buffer
  7. with a preceeding length byte.
  8. */
  9. parse arg expr
  10. if (expr = '?') then
  11.    do
  12.    do i = 2 to 7
  13.       'd "' strip(sourceline(i),'T', "0a"x) '"'
  14.    end
  15.    exit(0)
  16.    end
  17. options failat 3
  18. options results
  19. 'd ' expr
  20. stat = rc
  21. val = strip(result,'T',"0a"x)
  22. options
  23. if (stat ~= 0) then
  24.    do
  25.    'd "Error: can''t find' expr '"'
  26.    exit(0)
  27.    end
  28. val = strip(val)
  29. if (~datatype(val,'x')) then
  30.    do
  31.    'd "       ^------------should be an ''address''"'
  32.    exit(0)
  33.    end
  34. bptr = d2c(c2d(x2c(val))*4,4)
  35. bstr = import(offset(bptr,1),c2d(import(bptr,1)))
  36. do forever
  37.   y = verify(bstr, '"'||'0a0d00'x,'m')
  38.   if y = 0 then leave
  39.   c = substr(bstr,y,1)
  40.   if c = '"' then
  41.      bstr = left(bstr,y-1)||'\'||'05'x||substr(bstr,y+1)
  42.   else
  43.      bstr = left(bstr,y-1)||'\\'||translate(c,'nr0','0a0d00'x)||substr(bstr,y+1)
  44. end
  45. bstr = translate(bstr, '"', '05'x)
  46. 'd "0x'||c2x(bptr)||':  \"'||bstr||'\""'
  47. exit(0)
  48.